/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 *
 * $Id: WirelessData.hpp,v 1.6 2009-06-10 10:47:21 amaula Exp $
 * 
 * \file
 * \brief Protocol encoder/decoder header for the Wireless protocol.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _MACI_WIRELESSDATA_HPP_
#define _MACI_WIRELESSDATA_HPP_
#include "WirelessTypes.hpp"
#include "MaCIData.hpp"
#include "common/timestamp.hpp"
#include <vector>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace Wireless {

    /// Type for array of NodeSignal:s
    typedef std::vector<const TNodeSignal *> TNodeSignalPtrArray;
		
    /// Type for array of NodeID:s
    typedef std::vector<const TNodeID *> TNodeIDPtrArray;

    /// Type for array of NodeRange:s
    typedef std::vector<const TNodeRange *> TNodeRangePtrArray;

    /// Type for array of NodePosition:s
    typedef std::vector<const TNodePosition *> TNodePositionPtrArray;


    /** Wireless protocol parser.
     *
     * This class contains the methods for decoding/encoding a 
     * Wireless message.
     */
    class CWirelessData : public CMaCIData
    {
    public:
      CWirelessData();
      ~CWirelessData();

      // Interface for moving data around
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag);
      void Reset();
      void Print(const int level) const;


      /** Set timestamp element.
       * 
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set command element.
       * This function stores a element of type TCommand.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetCommand(const MaCI::Wireless::TCommand &aCmd);

      
      /** Add TNodeSignal element.
       *
       */
      bool AddNodeSignal(const MaCI::Wireless::TNodeSignal &aNodeSignal);
			
			
      /** Add TNodeSignal element.
       *
       */
      bool AddNodeID(const MaCI::Wireless::TNodeID &aNodeID);


      /** Add TNodeRange element.
       *
       */
      bool AddNodeRange(const MaCI::Wireless::TNodeRange &aNodeRange);


      /** Add TNodePosition element.
       *
       */
      bool AddNodePosition(const MaCI::Wireless::TNodePosition &aNodePosition);

     
      /** Add TMeasurementIndex element.
       *
       */
      bool SetMeasurementIndex(const MaCI::Wireless::TMeasurementIndex &aMeasurementIndex);

      /** Add TWirelessChannel element.
       *
       */
      bool AddWirelessChannel(const MaCI::Wireless::TWirelessChannel &aWirelessChannel);

      /** Get pointer to TTimestamp element.
       * 
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Common::TTimestamp *GetTimestamp(void) const;
      

      /** Get pointer to TCommand element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Wireless::TCommand *GetCommand(void) const;
      

      /** Get array of TNodeSignal element pointers.
       *
       */
      const MaCI::Wireless::TNodeSignalPtrArray &GetNodeSignalArray(void) const;
			

      /** Get array of TNodeID element pointers.
       *
       */
      const MaCI::Wireless::TNodeIDPtrArray &GetNodeIDArray(void) const;


      /** Get array of TNodeRange element pointers.
       *
       */
      const TNodeRangePtrArray &GetNodeRangeArray(void) const;
      
      
      /** Get array of TNodePosition element pointers.
       *
       */
      const MaCI::Wireless::TNodePositionPtrArray &GetNodePositionArray(void) const;

      /** Get pointer to TMeasurementIndex element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Wireless::TMeasurementIndex *GetMeasurementIndex(void) const;

      /** Get pointer to TWirelessChannel element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Wireless::TWirelessChannel *GetWirelessChannel(void) const;
      

    private:
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to timestamp if exists
      const TCommand *iCommandPtr; ///< Pointer to command if any.
      TNodeSignalPtrArray iNodeSignalArray; ///< Array of NodeSignal pointers.
      TNodeIDPtrArray iNodeIDArray; ///< Array of NodeID pointers.
      TNodeRangePtrArray iNodeRangeArray; ///< Array of NodeRange pointers.
      TNodePositionPtrArray iNodePositionArray; ///< Array of NodePosition pointers.
      const TMeasurementIndex *iMeasurementIndexPtr; /// Pointer to measurement index
      const TWirelessChannel *iWirelessChannelPtr; /// Pointer to wireless channel

      int iLastElementType; ///< Record of last added element
      
      CWirelessData(const CWirelessData &)
	: iTimestampPtr(NULL),
          iCommandPtr(NULL),
          iNodeSignalArray(),
          iNodeIDArray(),
          iNodeRangeArray(),
          iNodePositionArray(),
          iMeasurementIndexPtr(NULL),
          iWirelessChannelPtr(NULL),
          iLastElementType(-1) {}
      CWirelessData &operator=(const CWirelessData &) { return *this; }
    };
    
  }
}

#endif
